﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RTXSAPILib;
using System.Configuration;
using Enterprise.Service.User;
using Enterprise.Infrastructure;
namespace Enterprise.Service.Rtx
{
    /// <summary>
    /// 腾讯通信息服务
    /// </summary>
    public class RtxService
    {

        #region "RTX重置用户密码"
        /// <summary>
        /// RTX重置用户密码
        /// </summary>
        /// <param name="page"></param>
        /// <param name="_uLoginName"></param>
        public static void RTXModifyUser(System.Web.UI.Page page, string _uLoginName)
        {
            try
            {
                RTXSAPIRootObj RootObj = new RTXSAPIRootObj();
                RTXSAPIUserManager UserManagerObj = RootObj.UserManager;
                if (UserManagerObj.IsUserExist(_uLoginName))
                {
                    UserManagerObj.SetUserPwd(_uLoginName, _uLoginName);
                }
                else
                {
                    Utility.ShowMsg(page, "腾讯通中不存在该用户！");
                }
            }
            catch (Exception ex)
            {
                Utility.ShowMsg(page, ex.Message);
            }
        }
        #endregion

        #region "发送腾讯通消息提醒"
        /// <summary>
        /// 多人组成的字符串发送腾讯通消息提醒
        /// </summary>
        /// <param name="iUsers">人员</param>
        /// <param name="sTitle">标题</param>
        /// <param name="sContent">内容</param>
        /// <param name="bSendSms">是否发送短信</param>
        public static void SendRtxMessageServices(string iUsers, string sTitle, string sContent, bool bSendSms)
        {
            if (!string.IsNullOrEmpty(iUsers))
            {
                string[] users= iUsers.Split(',');
                if (users.Length > 1)
                {
                    for (int i = 0; i < users.Length; i++)
                    {
                        int uId = int.Parse(users[i].ToString());
                        if (uId != 0)
                        {
                            SendRtxMessageServices(uId, sTitle, sContent);
                        }
                    }
                }
            }
        }

        #endregion

        #region "发送腾讯通即时提醒消息+手机短信"
        /// <summary>
        ///  发送腾讯通即时提醒消息+手机短信功能
        /// </summary>
        /// <param name="iReveiver">用户Id</param>
        /// <param name="sTitle">标题</param>
        /// <param name="sContent">内容</param>
        /// <param name="bSendSms">是否发送手机短信</param>
        public static void SendRtxMessageServices(int iReveiver, string sTitle, string sContent, bool bSendSms)
        {
            UserService uService = new UserService();
            var query = uService.UserDisp(iReveiver);
            if (query != null)
            {
                if (query.USERID != 0 && !string.IsNullOrEmpty(query.ULOGINNAME))
                {
                    //声明一个腾讯通接口根对象      
                    //当为debug时候，则不发送腾讯通消息
                    bool rbool = bool.Parse(ConfigurationManager.AppSettings["Debug"].ToString());
                    if (rbool == false)
                    {
                        RTXSAPIRootObj RootObj = new RTXSAPIRootObj();
                        RootObj.SendNotify(query.ULOGINNAME, sTitle, 0, sContent);
                    }
                }
                if (bSendSms)
                {
                    SendSmsService(iReveiver, sContent);
                }
            }
        }

        #endregion

        #region 发送腾讯通即时消息"
        /// <summary>
        /// 发送腾讯通即时消息 By Caitou 2011/4/10  9:43
        /// </summary>
        /// <param name="sReveiver">接收人帐号</param>
        /// <param name="sTitle">标题</param>
        /// <param name="sContent">内容</param>
        /// UserName:Caitou
        /// Date：2011/4/10 9:43
        /// MachineName:CAITOU-PC
        public static void SendRtxMessageServices(string sReveiver, string sTitle, string sContent)
        {
            if (!string.IsNullOrEmpty(sReveiver))
            {
                //当为debug时候，则不发送腾讯通消息
                bool rbool = bool.Parse(ConfigurationManager.AppSettings["Debug"].ToString());
                if (rbool == false)
                {
                    //声明一个腾讯通接口根对象           
                    RTXSAPIRootObj RootObj = new RTXSAPIRootObj();
                    RootObj.SendNotify(sReveiver, sTitle, 0, sContent);
                }
            }

        }

        /// <summary>
        /// 发送腾讯通即时消息 By Caitou 2011/4/18  22:43
        /// </summary>
        /// <param name="iReveiver">接收人Id</param>
        /// <param name="sTitle">The s title.</param>
        /// <param name="sContent">Content of the s.</param>
        /// UserName:Caitou
        /// Date：2011/4/18 22:43
        /// MachineName:CAITOU-PC
        public static void SendRtxMessageServices(int iReveiver, string sTitle, string sContent)
        {
            //当为debug时候，则不发送腾讯通消息
            bool rbool = bool.Parse(ConfigurationManager.AppSettings["Debug"].ToString());
            if (rbool == false)
            {
                UserService uService = new UserService();
                var query = uService.UserDisp(iReveiver);
                if (query != null)
                {
                    if (query.USERID != 0)
                    {
                        SendRtxMessageServices(query.ULOGINNAME, sTitle, sContent);
                    }
                }
            }
        }

        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="iReveiver">接收人</param>
        /// <param name="sTitle">内容</param>
        public static void SendSmsService(int iReveiver, string sTitle)
        {

        }

        #endregion
    }
}
